package com.example.sport;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import com.example.sport.ui.notifications.NotificationsFragment;
import com.example.sport.ui.notifications.NotificationsFragment2;

public class TimeFragment extends Fragment {
int i=1;

    //创建视图
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_time, container, false);
        FragmentManager fragmentManager = getFragmentManager();

        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame_time
                ,new NotificationsFragment());
        fragmentTransaction.commit();

        View btn = inflate.findViewById(R.id.time_btn);


        btn.setOnClickListener(new View.OnClickListener() {

            boolean notific = false;

            @Override
            public void onClick(View v) {
                //点击小图标跳转
                    i++;
                    if (i%2==0){
                        ((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.pic3_1));
                    }else {
                        ((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.pic3_5));
                    }

                if(notific){
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.frame_time
                            ,new NotificationsFragment());
                    fragmentTransaction.commit();
                    notific = false;

                }else{
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.frame_time
                            ,new NotificationsFragment2());
                    fragmentTransaction.commit();
                    notific = true;
                }

            }

        });


        return inflate;  //要加载的layout文件
    }

}